<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>收货明细</title>
		<link rel="stylesheet" href="__PEAR__/component/pear/css/pear.css" />
		<style>
		.layui-input{width:150px;}
		.layui-form-label{width:auto;}
		.layui-form-item .layui-input-inline{width: 150px;}
		.inputdiv{display:flex;height: 38px;line-height: 38px;}
		.inputdiv i{position:absolute;right:10px;}
		.layui-table-cell .layui-table-link {color: #ff6a08!important;}}
		</style>
	</head>
	<body class="pear-container">
		<div class="layui-card">
			<div class="layui-card-body">
				<form class="layui-form" action="" id="searchform">
					<div class="layui-form-item">
					
					<div class="layui-row">
						<div class="layui-form-item layui-inline" id="date-range">
							<label class="layui-form-label">单据日期</label>
							<div class="layui-input-inline">
					          <input type="text" name="receive_date" value="" autocomplete="off" id="receive_date" class="layui-input" placeholder="">
					        </div>
					       
						</div>
						<div class="layui-form-item layui-inline">
								<label class="layui-form-label">采购收货单编号</label>
								<div class="layui-input-inline inputdiv">
									<input type="text" name="no" value="" autocomplete="off" class="layui-input" placeholder="请输入采购收货单编号">
								</div>
						</div>
						<div class="layui-form-item layui-inline">
								<label class="layui-form-label">分店仓库</label>
								<div class="layui-input-inline inputdiv">
									<input type="text" name="branch_no" id="branch_no" autocomplete="off" value="" placeholder="" class="layui-input" onfocus="showBranchs()">
									<i class="layui-icon layui-icon-home"></i>
								</div>
						</div>
						<div class="layui-form-item layui-inline">
							<button class="pear-btn pear-btn-md pear-btn-primary" lay-submit lay-filter="receive-query">
								<i class="layui-icon layui-icon-search"></i>
								查询
							</button>
							<button type="reset" class="pear-btn pear-btn-md" onclick="resetForm()">
								<i class="layui-icon layui-icon-refresh"></i>
								重置
							</button>
							<a class="pear-btn pear-btn-warming pear-btn-md" onclick="exportxls()">
							<i class="pear-icon pear-icon-chart-bar"></i>
							导出报表
							</a>
						</div>
					</div>
					</div>
					
				</form>
			</div>
		</div>
		<div class="layui-card">
			<div class="layui-card-body" id="receive-body">
				<table id="receive-table" lay-filter="receive-table"></table>
			</div>
		</div>
		<script type="text/html" id="statusTpl">
  			{{#  if(d.approve_flag ==1){ }}
    				<a class="layui-table-link">已审核</a>
  				{{#  } else { }}
    				未审核
  			{{#  } }}
		</script>
		<script src="__STATIC__/lib/layui/layui.js"></script>
		<script src="__PEAR__/component/pear/pear.js"></script>
		<script src="__STATIC__/js/admin/common.js"></script>
		<script>
			var branch_no="";
			var _layerIndex=null;
			var operator_url="{:U('Controls/operators')}";
			var branchs_url="{:U('Controls/branchs')}";
			
			layui.use(['table', 'form', 'jquery','common','laydate'], function() {
				let table = layui.table;
				let form = layui.form;
				let $ = layui.jquery;
				let common = layui.common;
				let laydate = layui.laydate;
				
			  	laydate.render({
					    elem: '#receive_date',
					    range: "~"
			    });

				let DATA_PATH = "/{$MODULE_NAME}/report/";

				let cols = [
					[
						{
							title: '单据编号',
							field: 'sheet_no',
							align: 'left',
							width: 180
						},
						{
							title: '单据金额',
							field: 'sheet_amt',
							align: 'left',
							width: 120
						},
						{
							title: '门店仓库',
							field: 'branch_name',
							align: 'left',
							width: 120
						},
						{
							title: '供应商',
							field: 'sp_name',
							align: 'left',
							width: 120
						},
						{
							title: '操作员',
							field: 'oper_name',
							align: 'left',
							width: 120
						},
						{
							title: '单据状态',
							field: 'order_status',
							align: 'left',
							width: 120
						},
						{
							title: '操作时间',
							field: 'oper_date',
							align: 'left',
							width: 120
						},
						{
							title: '审核状态',
							field: 'approve_flag',
							templet: '#statusTpl',
							align: 'left',
							width: 120
						}
					]
				]
				;
				
				table.render({
					elem: '#receive-table',
					url: DATA_PATH+"recList",
					page: true,
					cols: cols,
					height:600,
					skin: 'line',
					toolbar: '',
					defaultToolbar: [],
					done:function(res, curr, count){
						var _width=$("#receive-body").width();
						$("#receive-table").css("width", _width);
					}
				});
				
				form.on('submit(receive-query)', function(data) {
					table.reload('receive-table', {
						where: data.field,
						page:{curr:1}
					})
					return false;
				});
				
				//显示分店选择框
				window.showBranchs=function(){
					_layerIndex=openWin("分店仓库选择",branchs_url,"800px","600px");
				}
				
				//门店选择后的回调函数
				window.callBackBranch=function(data){
					
					var arr=new Array();
					for(var i in data){
						arr.push(data[i]['branch_no']);
					}
					
					$("#branch_no").val(arr.join(","));
					
					if(_layerIndex!=null){
						layer.close(_layerIndex);
					}
					_layerIndex=null;
				}
				
				//导出报表
				window.exportxls=function(){
					var param=$('#searchform').serialize();
					window.location.href="/{$MODULE_NAME}/report/recExport?"+param;
				}
			
				window.refresh = function(param) {
					table.reload('receive-table');
				}
			})
		</script>
	</body>
</html>
